<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>骡窝窝系统管理平台</title>
    <#include "../common/header.ftl"/>
    <script src="/js/plugins/common.js"></script>
    <script src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
        <#assign menu = "strategy" />
        <#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">平台用户管理</h1>
                </div>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/strategy/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                    </div>
                    <div class="form-group">
                        <label>关键字</label>
                        <input class="form-control" type="text"
                               name="keyword" value="${(qo.keyword)!}"  placeholder="请输入标题/副标题"/>
                        </input>
                    </div>

                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                    </div>
                    <a role="button" class="btn btn-success inputBtn">
                        <span class="glyphicon glyphicon-plus"></span> 添加攻略
                    </a>
                </form>
                <script type="text/javascript">
                    $("#query").click(function () {
                        $("#searchForm").submit();
                    })
                </script>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th width="200px">封面</th>
                        <th>攻略标题</th>
                        <th>副标题</th>
                        <th>所属地区</th>
                        <th>状态</th>
                        <th></th>
                    </tr>
                    </thead>
                    <tbody>
					<#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td><img src="${(entity.coverUrl)!}" width="100px"/> </td>
                        <td>${entity.title}</td>
                        <td>${entity.subTitle}</td>
                        <td>${entity.place.name}</td>
                        <td>${entity.stateName}</td>
                        <td>
                            <a role="button" class="btn btn-success inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-leaf"></span> 修改
                            </a>
                        </td>
                    </tr>
					</#list>
                    </tbody>
                </table>
               <#include "../common/page.ftl"/>
            </div>
            <div id="strategyModal" class="modal" tabindex="-1" role="dialog">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">编辑/增加</h4>
                        </div>
                        <div class="modal-body">
                            <form id="strategyForm" class="form-horizontal" method="post" action="/strategy/saveOrUpdate.do" enctype="multipart/form-data" style="margin: -3px 118px">
                                <input type="hidden" name="id"/>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">标题</label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="title" placeholder="标题">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">副标题</label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="subTitle" placeholder="副标题">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">封面</label>
                                    <div class="col-sm-6">
                                        <img width="200px" id="coverImg"/><!--用来显示-->
                                        <input type="hidden" name="coverUrl"  ><!--用来提交-->
                                        <input type="file" class="form-control"  name="file" ><!--用来上传图片-->
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">所属地区</label>
                                    <div class="col-sm-6">
                                        <select class="form-control" autocomplete="off" name="place.id" >
                                           <#list places as p>
                                               <option value="${p.id}">${p.name}</option>
                                           </#list>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">状态</label>
                                    <div class="col-sm-6">
                                        <select class="form-control" autocomplete="off" name="state" >
                                            <option value="-1">禁用</option>
                                            <option value="0">正常</option>
                                            <option value="1">推荐</option>
                                        </select>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <a href="javascript:void(0);" class="btn btn-primary" id="saveBtn" aria-hidden="true">保存</a>
                            <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
                        </div>
                    </div>
                </div>

            </div>
    </div>
</div>
<style>
    #contentModal img{
        width: 100%;
    }
    #contentModal .modal-body{
        max-height: 600px;
        overflow-y: scroll;
    }
</style>
<script type="text/javascript">

    $(".inputBtn").click(function () {
        var json = $(this).data("json");
        $("#strategyForm input").val("");
        //回显数据
        if (json) {
            $("#strategyForm input[name='id']").val(json.id);
            $("#strategyForm input[name='title']").val(json.title);
            $("#strategyForm input[name='subTitle']").val(json.subTitle);
            $("#coverImg").attr("src",json.coverUrl);
            //回显到隐藏域,用于提交表单,因为img不是表单的属性,不能用来提交
            $("#strategyForm input[name='coverUrl']").val(json.coverUrl);
            $("#strategyForm select[name='place.id']").val(json.placeId);
            $("#strategyForm select[name='state']").val(json.state);
        }
        $("#strategyModal").modal("show")
    });
    $("#saveBtn").click(function () {
        $("#strategyForm").ajaxSubmit(function (data) {
            doSuccess();
        })
    })
</script>
</body>
</html>
